import { DataTypes, Model } from 'sequelize'
import sequelize from './db'

export interface IQuestion {
    id: number
    teachCaseId: number
    type: 'singleChoice' | 'multiChoice' | 'shortAnswer'
    trigger: string
    point: string
    content: string
    options: {
        content: string
        id: string
    }[]
    answer: string
}

class Question extends Model {
    declare id: number
    declare teachCaseId: number
    declare type: 'singleChoice' | 'multiChoice' | 'shortAnswer'
    declare trigger: string;
    declare point: string;
    declare content: string
    declare options: {
        content: string
        id: string
    }
    declare answer: string
    
}

Question.init(
    {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true,
        },
        teachCaseId: {
            type: DataTypes.INTEGER,
            comment: '案例id',
        },
        type: {
            type: DataTypes.STRING,
            comment: '类型, 单选题singleChoice',
        },
        trigger: {
            type: DataTypes.STRING,
            comment: '触发时机',
        },
        point: {
            type: DataTypes.STRING,
            comment: '知识点',
        },
        options: {
            type: DataTypes.JSON,
            comment: '选项, 只有单选题，多选题有选项',
        },
        content: {
            type: DataTypes.STRING,
            comment: '问题',
        },
        answer: {
            type: DataTypes.STRING,
            comment: '答案',
        },
    },
    {
        // 这是其他模型参数
        sequelize, // 我们需要传递连接实例
        modelName: 'question', // 我们需要选择模型名称
        paranoid: true,
    }
)

export default Question
